﻿using System;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata;

namespace Test_QianBZ.DataAccess
{
    public partial class eatContext : DbContext
    {
        public eatContext()
        {
        }

        public eatContext(DbContextOptions<eatContext> options)
            : base(options)
        {
        }

        public virtual DbSet<TbEatlog> TbEatlog { get; set; }
        public virtual DbSet<TbMenu> TbMenu { get; set; }
        public virtual DbSet<TbPerson> TbPerson { get; set; }

        protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
        {
            if (!optionsBuilder.IsConfigured)
            {
                optionsBuilder.UseSqlServer("Server=118.190.110.13,1433;Database=eat;user id=sa;pwd=Qb123456.");
            }
        }

        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            modelBuilder.Entity<TbEatlog>(entity =>
            {
                entity.HasKey(e => e.LogId);

                entity.ToTable("tb_eatlog");

                entity.Property(e => e.LogId).HasColumnName("logID");

                entity.Property(e => e.EatCount).HasColumnName("eatCount");

                entity.Property(e => e.EatTime)
                    .HasColumnName("eatTIme")
                    .HasColumnType("datetime");

                entity.Property(e => e.FoodId).HasColumnName("foodID");

                entity.Property(e => e.PersonId).HasColumnName("personID");
            });

            modelBuilder.Entity<TbMenu>(entity =>
            {
                entity.HasKey(e => e.FoodId);

                entity.ToTable("tb_menu");

                entity.Property(e => e.FoodId).HasColumnName("foodId");

                entity.Property(e => e.FoodName)
                    .HasColumnName("foodName")
                    .HasMaxLength(50);
            });

            modelBuilder.Entity<TbPerson>(entity =>
            {
                entity.HasKey(e => e.PersonId);

                entity.ToTable("tb_person");

                entity.Property(e => e.PersonId).HasColumnName("personId");

                entity.Property(e => e.PersonName)
                    .HasColumnName("personName")
                    .HasMaxLength(10);
            });
        }
    }
}
